# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Brad Fanella <bradfanella@archlinux.us>
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
# Contributor: William Rea <sillywilly@gmail.com>

pkgname=libgeotiff
pkgver=1.7.1
pkgrel=2
pkgdesc="A TIFF based interchange format for georeferenced raster imagery"
arch=(loong64 x86_64)
url="https://github.com/OSGeo/libgeotiff"
license=(custom)
depends=(libtiff proj libjpeg-turbo zlib)
changelog=$pkgname.changelog
source=(https://github.com/OSGeo/$pkgname/releases/download/$pkgver/$pkgname-$pkgver.tar.gz
        $pkgname-proj-9.1.1-part1.patch::https://github.com/OSGeo/libgeotiff/commit/f4b2b195c2d1.patch
        $pkgname-proj-9.1.1-part2.patch::https://github.com/OSGeo/libgeotiff/commit/468e2a178fa2.patch)
sha256sums=('05ab1347aaa471fc97347d8d4269ff0c00f30fa666d956baba37948ec87e55d6'
            'afa402635f5efb73c4e0773e1e091a34104c405f452f8cf7d69ce188079ca9c6'
            'bac7e47e6f0a8793ebf19fcfd5791d75e772e5e656100374e4e8e70e75990b70')

prepare() {
  cd $pkgname-$pkgver
  autoreconf -vfi

  # https://github.com/OSGeo/libgeotiff/issues/81
  patch -Np2 -i ../$pkgname-proj-9.1.1-part1.patch
  patch -Np2 -i ../$pkgname-proj-9.1.1-part2.patch
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --with-jpeg=yes --with-zlib=yes
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd $pkgname-$pkgver
  make check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="${pkgdir}" install
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
